package im.notify.server;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolEncoder;
import org.apache.mina.filter.codec.ProtocolEncoderOutput;

public class MyTextLineEncoder implements ProtocolEncoder {

	public void dispose(IoSession arg0) throws Exception {

	}

	public void encode(IoSession session, Object message, ProtocolEncoderOutput out)
			throws Exception {
		String s =null;
		if (message instanceof String) {
			s = (String) message;
		}
		if (s != null) {
			IoBuffer ioBuffer = IoBuffer.allocate(s.length());
			ioBuffer.setAutoExpand(true);
			ioBuffer.put((s+"\b").getBytes("utf-8"));
			ioBuffer.flip();
			out.write(ioBuffer);
		}
	}

}
